package service.impl;

import dao.UserDao;
import model.User;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.UserService;
import util.MD5Util;
import util.ReturnResultUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by gable on 2018/6/20.
 */
@Service
public class UserServiceImpl implements UserService{

    private final Log logger = LogFactory.getLog(this.getClass());

    @Autowired
    private UserDao userDao;

    @Override
    public ReturnResultUtil login(String username, String password) {
        Map<String ,String > paramMap = new HashMap<>();
        paramMap.put("username",username);
        paramMap.put("password", MD5Util.md5(password));
        User user = userDao.queryUserByLogin(paramMap);
        if(user == null){
            return new ReturnResultUtil(0,"帐号或密码错误");
        }
        return new ReturnResultUtil(1,"登录成功",user);
    }
}
